/*
 * @Author: your name
 * @Date: 2021-04-17 14:32:10
 * @LastEditTime: 2021-04-17 14:32:38
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \vue-xmall\src\store\home.js
 */
import {
  reqNavList,
  reqSwiperList
} from '@/api/index'
const state = {
  navList: [],
  homeInfo:[]
}

const mutations = {
  //存储导航列表
  RECEIVED_NAVLIST(state, navList) {
    state.navList = navList
  },
  //存储轮播列表
  RECEIVED_SWIPERLIST(state,homeInfo){
    state.homeInfo = homeInfo
  }

}

const actions = {
  //获取导航列表数据
  async getNavList({
    commit
  }) {
    const navListData = await reqNavList()
    if (navListData.code === 200) {
      commit('RECEIVED_NAVLIST', navListData.data)
    }
  },

  //获取轮播图数据
  async getSwiperList({commit}){
    const homeInfoData = await reqSwiperList()
    if(homeInfoData.code === 200){
      commit('RECEIVED_SWIPERLIST',homeInfoData.result)
    }
  }
}
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}